#include<iostream>
#include<algorithm>
#include<unordered_set>
using namespace std;
const int N = 52;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	int n;
	cin >> n;
	unordered_set<int> s[N];
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		while (x--)
		{
			int y;
			cin >> y;
			s[i].insert(y);
		}
	}
	int k;
	cin >> k;
	while (k--)
	{
		int x, y;
		int com = 0;
		cin >> x >> y;
		for (const auto& it : s[y])
		{
			if (s[x].count(it))
			{
				com++;
			}
		}
		int res = s[x].size() + s[y].size() - com;
		printf("%.1lf%%\n", com*1.0/res*100);
	}
	return 0;
}